package com.glsc.ngateway.common.base.repo.mysql.opmanage.report.regulatory;

import com.alibaba.fastjson.JSONObject;
import com.glsc.ngateway.common.base.domain.mysql.opmanage.report.regulatory.RegRptMain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

/**
 * @author: qiyr
 * @date: 2022/4/21 13:36
 * @description: 监管报送数据主数据访问层
 */
@Repository
public interface RegRptMainRepo extends JpaRepository<RegRptMain, BigInteger>, JpaSpecificationExecutor<RegRptMain> {

    @Query(value = "select  " +
            "           trrm.id," +
            "           trrm.rpt_define_id," +
            "           trrm.bizdate," +
            "           trrm.dimension1," +
            "           (" +
            "           select" +
            "               max(trrcr.status)" +
            "           from" +
            "               glsc_data.t_reg_rpt_checkrules_result trrcr" +
            "           where" +
            "               trrcr.main_id = trrm.id" +
            "               and trrcr.is_del = 0) as check_status," +
            "           trrm.operator," +
            "           trrm.create_time" +
            "       from" +
            "           glsc_data.t_reg_rpt_main trrm" +
            "       join" +
            "           glsc_data.t_reg_rpt_define trrd" +
            "       on" +
            "           trrm.rpt_define_id = trrd.id" +
            "       where" +
            "           trrm.status = 0" +
            "           and trrm.rpt_define_id in (:defineIdList)" +
            "           and trrm.bizdate = :bizdate" +
            "       order by trrm.id", nativeQuery = true)
    List<JSONObject> queryInfo(@Param("defineIdList") List<BigInteger> defineIdList, @Param("bizdate") String bizdate);

}
